package com.jxstjh.conch.support.utils;

import com.dtp.core.DtpRegistry;
import com.dtp.core.thread.DtpExecutor;
import com.jxstjh.conch.support.config.ThreadPoolExecutorShutdownConfig;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 线程池工具类
 */
public class ThreadPoolUtil {

    @Autowired
    private ThreadPoolExecutorShutdownConfig shutdownConfig;

    private static final String SOURCE_NAME = "conch";


    /**
     * 1. 将当前线程池 加入到 动态线程池内
     * 2. 注册 线程池 被Spring管理，优雅关闭
     */
    public void register(DtpExecutor dtpExecutor) {
        DtpRegistry.register(dtpExecutor, SOURCE_NAME);
        shutdownConfig.registryExecutor(dtpExecutor);
    }
}